<template>
  <div class="aaa">
    <el-upload
      class="avatar-uploader"
      action="https://api.xstarlife.com/systemapp/upload/singleFileUpload"
      :show-file-list="false"
      :headers="{ uploadScene: 'avatar' }"
      :on-success="handleAvatarSuccess"
      :before-upload="beforeAvatarUpload"
    >
      <img v-if="imageUrl" :src="imageUrl" class="avatar" />
      <i v-else class="el-icon-plus avatar-uploader-icon"></i>
    </el-upload>
  </div>
</template>

<script>
export default {
  data() {
    return {
      imageUrl: ""
    };
  },
  methods: {
    handleAvatarSuccess(res) {
      const { data } = res;
      this.imageUrl = data;
    }
  }
};
</script>

<style lang="scss" scoped>
.aaa {
  width: 100%;
  height: 600px;
  background-color: #fff;
}
/deep/ .avatar-uploader .el-upload {
  width: 100px;
  height: 100px;
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}
.avatar {
  width: 178px;
  height: 178px;
  display: block;
}
</style>
